import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import { getTests, QueryTestsSchema, UpdateTestSchema, updateTest } from "../queries/tests";

const app = new Hono()
  .get("/", zValidator("query", QueryTestsSchema), async (c) => {
    const params = c.req.valid("query");
    const tests = await getTests(params);
    return c.json({ ok: true, data: tests }, 200);
  })
  .post("/", zValidator("json", UpdateTestSchema), async (c) => {
    const params = c.req.valid("json");
    const test = await updateTest(params);
    return c.json({ ok: true, data: test }, 201);
  });

export default app;
